using MilkShake;
using UnityEngine;
using UnityEngine.UI;

public class CellPhone : MonoBehaviour
{
	public static CellPhone Instance;

	public ShakePreset shake;

	public GameObject crack;

	public Rigidbody2D rb;

	public AudioClip groundAudio;

	public AudioClip pickupAudio;

	private float lastHit;

	private void Awake()
	{
		if (Instance != null)
		{
			Object.Destroy(Instance.gameObject);
		}
		Instance = this;
	}

	private void OnCollisionEnter2D(Collision2D collision)
	{
		if (lastHit != 0f && lastHit + 5f > Time.time)
		{
			return;
		}
		lastHit = Time.time;
		Shaker.ShakeAll(shake);
		Object.Instantiate(crack, base.transform.position, Quaternion.identity);
		rb.velocity = Vector2.zero;
		Player.Instance.audioSource.PlayOneShot(groundAudio);
		foreach (Zombie zombie in CampaignGame.Instance.zombies)
		{
			if ((bool)zombie.animator)
			{
				string text = null;
				string[] array = new string[3] { "fallDownFront", "fallDownBack", "kneelDown" };
				text = array[Random.Range(0, array.Length)];
				zombie.Knockback(0f, text);
			}
		}
	}

	private void FixedUpdate()
	{
		if (!(Vector2.Distance(Player.Instance.transform.position, base.transform.position) < 0.5f))
		{
			return;
		}
		Player.Instance.audioSource.PlayOneShot(pickupAudio);
		if (!CampaignGame.Instance.isPlayground)
		{
			foreach (Transform item in CampaignGame.Instance.itemListView.transform)
			{
				if (item.name == "Cellphone")
				{
					item.GetComponent<Image>().color = Color.black;
					item.Find("Count").GetComponent<Text>().text = "1";
					break;
				}
			}
		}
		Instance = null;
		Object.Destroy(base.gameObject);
	}
}
